﻿using Swifter.RW;
using System.Numerics;

namespace RpcHelper.Json
{
    internal class BigIntegerType : IValueInterface<BigInteger>
    {
        public BigIntegerType()
        {
        }

        public BigInteger ReadValue(IValueReader valueReader)
        {
            string val = valueReader.ReadString();
            if (val.IsNull())
            {
                return BigInteger.Zero;
            }
            return BigInteger.Parse(val);
        }

        public void WriteValue(IValueWriter valueWriter, BigInteger value)
        {
            if (value != BigInteger.Zero)
            {
                valueWriter.WriteString(value.ToString());
            }
        }
    }
}
